
#include "Display_DF_Extensions.h"

#include <string.h>
#include <stdio.h>


static void fillAngle(char *str, AngleSegment angle, bool isLongitude){
	static const char degreeChar[] = {0xb0, 0x00};
	char tmpStr[16];
	
	if(isLongitude){
		sprintf(tmpStr, "%03i", angle.degree);
	}else{
		sprintf(tmpStr, "%02i", angle.degree);
	}
	strcat(str, tmpStr);
	strcat(str, degreeChar);
	
	sprintf(tmpStr, "%02i'", angle.minute);
	strcat(str, tmpStr);

	sprintf(tmpStr, "%02i\"", angle.second);
	strcat(str, tmpStr);
}

void DFDrawLongitude(DFBuffer *this, SFPoint pos, DFFontStyle style, Longitude longitude){
	char str[16];

	if(longitude.direction==DirectionEast){
		strcpy(str, "E");
	}else{
		strcpy(str, "W");
	}
	
	fillAngle(str, longitude.angle, 1);

	DFDrawString(this, pos, style, str);
}

void DFDrawLatitude(DFBuffer *this, SFPoint pos, DFFontStyle style, Latitude latitude){
	char str[16];

	if(latitude.direction==DirectionNorth){
		strcpy(str, "N ");
	}else{
		strcpy(str, "S ");
	}
	
	fillAngle(str, latitude.angle, 0);

	DFDrawString(this, pos, style, str);
}
